package com.xdap.common.util;

import com.google.common.collect.Maps;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.WeekFields;
import java.util.*;

public class ComDateUtil {
    public ComDateUtil() {
    }

    public static LocalDate getQuarterStart(LocalDate localDate) {
        localDate = localDate.withDayOfMonth(1);
        long month = (long) localDate.getMonth().getValue();
        if (1L <= month && month <= 3L) {
            localDate = localDate.withMonth(1);
        } else if (4L <= month && month <= 6L) {
            localDate = localDate.withMonth(4);
        } else if (7L <= month && month <= 9L) {
            localDate = localDate.withMonth(7);
        } else {
            localDate = localDate.withMonth(10);
        }

        return localDate;
    }

    public static LocalDate getQuarterEnd(LocalDate localDate) {
        localDate = localDate.withDayOfMonth(localDate.lengthOfMonth());
        long month = (long) localDate.getMonth().getValue();
        if (1L <= month && month <= 3L) {
            localDate = localDate.withMonth(3);
        } else if (4L <= month && month <= 6L) {
            localDate = localDate.withMonth(6);
        } else if (7L <= month && month <= 9L) {
            localDate = localDate.withMonth(9);
        } else {
            localDate = localDate.withMonth(12);
        }

        return localDate;
    }

    public static void main(String[] args) {
        LocalDate today = LocalDate.now(); // 获取当前日期
        LocalDate monday = today.minusDays(today.getDayOfWeek().getValue() % 7 + 6);


        // 获取上周一的日期
        Map lastWeekMap = Maps.newHashMap();
        int mondayDayOfMonth = monday.getDayOfMonth();

        lastWeekMap.put(monday.getDayOfWeek().getValue(), monday);
        for (int i = 1; i < 7; i++) {
            monday = monday.plusDays(1);
            lastWeekMap.put(monday.getDayOfWeek().getValue(), monday);
        }


        WeekFields weekFields = WeekFields.of(Locale.getDefault()); // 获取默认语言环境的周定义
        int weekOfMonth = monday.get(weekFields.weekOfMonth()); // 获取本周是本月第几周
        System.out.println("本周是本月第 " + weekOfMonth + " 周");
        String yyyy = formatDate(ComDateUtil.parseDate("2023-07-02"), "yyyy");
        String mmmm = formatDate(ComDateUtil.parseDate("2023-07-02"), "MM");
        String s = yyyy + Integer.parseInt(mmmm);
        String yyyymm = formatDate(ComDateUtil.parseDate("2023-07-02"), "yyyyMM");
        String lastMonth = ComDateUtil.getLastMonth();
        // 获取当前日期
        Calendar calendar = Calendar.getInstance();
        // 减去一个月
        calendar.add(Calendar.MONTH, -1);
        // 获取上个月的年份和月份
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1; // 月份是从 0 开始的，需要加 1
        // 输出结果
        System.out.println("上个月的月份数据：" + month);
        calendar = Calendar.getInstance();
        // 减去一个月
        calendar.add(Calendar.MONTH, +1);
        // 获取上个月的年份和月份
        int year1 = calendar.get(Calendar.YEAR);
        int month1 = calendar.get(Calendar.MONTH) + 1; // 月份是从 0 开始的，需要加 1

        // 输出结果
        System.out.println("下个月的月份数据：" + month1);

        Date date = parseDate("2022-11-14");
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate localDate = LocalDate.of(2021, 10, 17);
        LocalDate startWeekDay = localDate.with(ChronoField.DAY_OF_WEEK, 1L);
        LocalDate endWeekDay = localDate.with(ChronoField.DAY_OF_WEEK, 7L);
        System.out.printf("当前周周一：%s, 当前周周日：%s%n", format.format(startWeekDay), format.format(endWeekDay));
        LocalDate startMonthDay = localDate.with(ChronoField.DAY_OF_MONTH, 1L);
        LocalDate endMonthDay = localDate.withDayOfMonth(localDate.lengthOfMonth());
        System.out.printf("月份的第一天：%s, 月份的最后一天：%s%n", format.format(startMonthDay), format.format(endMonthDay));
        LocalDate startQuarterDay = getQuarterStart(localDate);
        LocalDate endQuarterDay = getQuarterEnd(localDate);
        System.out.printf("季度第一天：%s, 季度最后一天：%s%n", format.format(startQuarterDay), format.format(endQuarterDay));
        LocalDate startYearDay = localDate.with(ChronoField.DAY_OF_YEAR, 1L);
        LocalDate endYearDay = localDate.with(ChronoField.DAY_OF_YEAR, (long) localDate.lengthOfYear());
        System.out.printf("年份第一天：%s, 年份最后一天：%s%n", format.format(startYearDay), format.format(endYearDay));

        boolean b = compareDate("2023-05-02", "2023-06-08");
        int diffYear = getDiffYear("2023-05-02", "2023-09-08");
        int diffMonth = getDiffMonth("2023-05-02", "2023-09-08");
        int diffMonth1 = getDiffMonth("2023-05-02", "2024-01-08");
        long daySub = getDaySub("2023-05-02", "2024-06-08");
        String afterDayDate = getAfterDayDate("25");
        String afterDayWeek = getAfterDayWeek("12");
        String firstDayOfMonth = getFirstDayOfMonth(2023, 11);
        String lastDayOfMonth = getLastDayOfMonth(2024, 10);
        String firstDayOfNextMonth = getFirstDayOfNextMonth(2024, 10);
        String lastDayOfNextMonth = getLastDayOfNextMonth(2024, 10);
        String currentLastDayOfMonth = getCurrentLastDayOfMonth("2023-10-12");
        String currentFirstDayOfMonth = getCurrentFirstDayOfMonth("2023-10-12");
        String nextMonthFirstDay = getNextMonthFirstDay("2023-10-12");
        Date dayBegin = getDayBegin();
        String format1 = format(getDayBegin(), "yyyy-MM-dd");
        String format2 = format(getDayEnd(), "yyyy-MM-dd");
        Date dateAfterYear = getDateAfterYear(new Date(), 2024);
        String format3 = format(dateAfterYear, "yyyy-MM-dd");
        Date dateAfterDays = getDateAfterDays(new Date(), 5);
        String format4 = format(dateAfterDays, "yyyy-MM-dd");
        Date dateAfterDay = getDateAfterDay(new Date(), 5);
        String format5 = format(dateAfterDay, "yyyy-MM-dd");
        String quarter = getQuarter("10");
        List<String> everyDay = findEveryDay("2023-05-02", "2023-09-08");
        YearMonth thisMonth = getThisMonth();
        YearMonth nextMonth1 = getNextMonth1();
        String nextMonth = getNextMonth();
        String lastYearMonth = getLastYearMonth();
        String nextYearMonth = getNextYearMonth();
        System.out.println("1111111111111");

    }

    public static int getWeekOfMonth(LocalDate localDate) {
        WeekFields weekFields = WeekFields.of(Locale.getDefault()); // 获取默认语言环境的周定义
        int weekOfMonth = localDate.get(weekFields.weekOfMonth());
        return weekOfMonth;
    }

    public static YearMonth getThisMonth() {
        LocalDate today = LocalDate.now(); // 获取当前日期
        return YearMonth.from(today); // 获取当前月份
    }

    public static YearMonth getNextMonth1() {
        LocalDate today = LocalDate.now(); // 获取当前日期
        return YearMonth.from(today).plusMonths(1); // 获取当前月份
    }

    public static String getYear() {
        return formatDate(new Date(), "yyyy");
    }

    public static String getMonth() {
        return formatDate(new Date(), "MM");
    }

    /**
     * @Description 获取上个月月份
     * @Date 2023/10/19 15:43
     * @Author shangsheng.li
     **/
    public static String getLastMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        int month = calendar.get(Calendar.MONTH) + 1;
        return String.valueOf(month);
    }

    /**
     * @Description 获取下个月月份
     * @Date 2023/10/19 15:43
     * @Author shangsheng.li
     **/
    public static String getNextMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, +1);
        int month = calendar.get(Calendar.MONTH) + 1;
        return String.valueOf(month);
    }

    /**
     * @Description 获取下个月年月
     * @Date 2023/10/24 9:03
     * @Author shangsheng.li
     **/
    public static String getNextYearMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, +1);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        return year + "" + month;
    }

    /**
     * @Description 获取上个月年月
     * @Date 2023/10/24 9:03
     * @Author shangsheng.li
     **/
    public static String getLastYearMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        return year + "" + month;
    }

    public static String getYear(Date date) {
        return formatDate(date, "yyyy");
    }

    public static String getMonth(Date date) {
        return formatDate(date, "MM");
    }

    public static String getDay() {
        return formatDate(new Date(), "yyyy-MM-dd");
    }

    public static String getDay(Date date) {
        return formatDate(date, "yyyy-MM-dd");
    }

    public static String getDays() {
        return formatDate(new Date(), "yyyyMMdd");
    }

    public static String getDays(Date date) {
        return formatDate(date, "yyyyMMdd");
    }

    public static String getTime() {
        return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
    }

    public static String getMsTime() {
        return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
    }

    public static String getAllTime() {
        return formatDate(new Date(), "yyyyMMddHHmmss");
    }

    public static String getAllMSTime() {
        return formatDate(new Date(), "yyyyMMddHHmmssSSS");
    }

    public static String getTime(Date date) {
        return formatDate(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String formatDate(Date date, String pattern) {
        String formatDate = null;
        if (StringUtils.isNotBlank(pattern)) {
            formatDate = DateFormatUtils.format(date, pattern);
        } else {
            formatDate = DateFormatUtils.format(date, "yyyy-MM-dd");
        }

        return formatDate;
    }

    public static boolean compareDate(String s, String e) {
        if (parseDate(s) != null && parseDate(e) != null) {
            return parseDate(s).getTime() >= parseDate(e).getTime();
        } else {
            return false;
        }
    }

    public static Date parseDate(String date) {
        return parse(date, "yyyy-MM-dd");
    }

    public static Date parseTime(String date) {
        return parse(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static Date parse(String date, String pattern) {
        try {
            return DateUtils.parseDate(date, new String[]{pattern});
        } catch (ParseException var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static String format(Date date, String pattern) {
        return DateFormatUtils.format(date, pattern);
    }

    public static Timestamp format(Date date) {
        return new Timestamp(date.getTime());
    }

    public static boolean isValidDate(String s) {
        return parse(s, "yyyy-MM-dd HH:mm:ss") != null;
    }

    public static boolean isValidDate(String s, String pattern) {
        return parse(s, pattern) != null;
    }

    /**
     * @Description 获取两个日期相差年份
     * @Date 2023/10/19 15:54
     * @Author shangsheng.li
     **/
    public static int getDiffYear(String startTime, String endTime) {
        DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");

        try {
            int years = (int) ((fmt.parse(endTime).getTime() - fmt.parse(startTime).getTime()) / 86400000L / 365L);
            return years;
        } catch (Exception var4) {
            return 0;
        }
    }


    /**
     * @Description 获取两个日期的月份差
     * @Date 2023/10/19 16:17
     * @Author shangsheng.li
     **/
    public static int getDiffMonth(String startTime, String endTime) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate date1 = LocalDate.parse(startTime, formatter);
        LocalDate date2 = LocalDate.parse(endTime, formatter);
        // 使用 Period 计算两个日期之间的差异
        Period period = Period.between(date1, date2);
        return period.getMonths();
    }

    /**
     * @Description 获取两个日期之间的天数和
     * @Date 2023/10/19 15:57
     * @Author shangsheng.li
     **/
    public static long getDaySub(String beginDateStr, String endDateStr) {
        long day = 0L;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date beginDate = null;
        Date endDate = null;

        try {
            beginDate = format.parse(beginDateStr);
            endDate = format.parse(endDateStr);
        } catch (ParseException var8) {
            var8.printStackTrace();
        }

        day = (endDate.getTime() - beginDate.getTime()) / 86400000L;
        return day;
    }

    public static Long getDaySub(Date beginTime, Date endTime) {
        return (endTime.getTime() - beginTime.getTime()) / 86400000L;
    }

    /**
     * @Description 获取几天后的日期
     * @Date 2023/10/19 15:58
     * @Author shangsheng.li
     **/
    public static String getAfterDayDate(String days) {
        int daysInt = Integer.parseInt(days);
        Calendar calendar = Calendar.getInstance();
        calendar.add(5, daysInt);
        Date date = calendar.getTime();
        SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStr = sdfd.format(date);
        return dateStr;
    }

    /**
     * @Description 获取几天后是周几
     * @Date 2023/10/19 15:59
     * @Author shangsheng.li
     **/
    public static String getAfterDayWeek(String days) {
        int daysInt = Integer.parseInt(days);
        Calendar calendar = Calendar.getInstance();
        calendar.add(5, daysInt);
        Date date = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("E");
        String dateStr = sdf.format(date);
        return dateStr;
    }

    public static String time2String(String seconds, String format) {
        if (seconds != null && !seconds.isEmpty() && !"null".equals(seconds)) {
            if (format == null || format.isEmpty()) {
                format = "yyyy-MM-dd HH:mm:ss";
            }

            SimpleDateFormat sdf = new SimpleDateFormat(format);
            return sdf.format(new Date(Long.parseLong(seconds + "000")));
        } else {
            return "";
        }
    }

    public static Long str2TimeStamp(String date_str, String format) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            return sdf.parse(date_str).getTime() / 1000L;
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static Long str2TimeStampMillions(String date_str, String format) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            return sdf.parse(date_str).getTime();
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    /**
     * @Description 获取传入日期月份的第一天
     * @Date 2023/10/19 16:00
     * @Author shangsheng.li
     **/
    public static String getFirstDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(1, year);
        cal.set(2, month - 1);
        int firstDay = cal.getActualMinimum(5);
        cal.set(5, firstDay);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String firstDayOfMonth = sdf.format(cal.getTime());
        return firstDayOfMonth;
    }

    /**
     * @Description 获取本月最后一天
     * @Date 2023/10/19 16:00
     * @Author shangsheng.li
     **/
    public static String getLastDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(1, year);
        cal.set(2, month - 1);
        int firstDay = cal.getActualMaximum(5);
        cal.set(5, firstDay);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String firstDayOfMonth = sdf.format(cal.getTime());
        return firstDayOfMonth;
    }

    /**
     * @Description 获取下个月第一天
     * @Date 2023/10/19 16:01
     * @Author shangsheng.li
     **/
    public static String getFirstDayOfNextMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month);
        int firstDay = cal.getActualMinimum(Calendar.DATE);
        cal.set(Calendar.DATE, firstDay);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String firstDayOfMonth = sdf.format(cal.getTime());
        return firstDayOfMonth;
    }

    /**
     * @Description 获取下个月最后一天
     * @Date 2023/10/19 16:01
     * @Author shangsheng.li
     **/
    public static String getLastDayOfNextMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month);
        int firstDay = cal.getActualMaximum(Calendar.DATE);
        cal.set(Calendar.DATE, firstDay);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String firstDayOfMonth = sdf.format(cal.getTime());
        return firstDayOfMonth;
    }

    public static String getCurrentLastDayOfMonth(String pattern) {
        Calendar cale = Calendar.getInstance();
        cale.add(2, 1);
        cale.set(5, 0);
        if (pattern == null || pattern.isEmpty()) {
            pattern = "yyyy-MM-dd";
        }

        SimpleDateFormat format = new SimpleDateFormat(pattern);
        String firstday = format.format(cale.getTime());
        return firstday;
    }

    public static String getCurrentFirstDayOfMonth(String pattern) {
        Calendar cale = Calendar.getInstance();
        cale.add(2, 0);
        cale.set(5, 1);
        if (pattern == null || pattern.isEmpty()) {
            pattern = "yyyy-MM-dd";
        }

        SimpleDateFormat format = new SimpleDateFormat(pattern);
        String firstday = format.format(cale.getTime());
        return firstday;
    }

    public static String getNextMonthFirstDay(String pattern) {
        Calendar cale = Calendar.getInstance();
        cale.add(2, 1);
        cale.set(5, 1);
        if (pattern == null || pattern.isEmpty()) {
            pattern = "yyyy-MM-dd";
        }

        SimpleDateFormat format = new SimpleDateFormat(pattern);
        String firstday = format.format(cale.getTime());
        return firstday;
    }

    public static String getFirstOfWeek(String dataStr, String dateFormat, String resultDateFormat) {
        Calendar cal = Calendar.getInstance();

        try {
            cal.setTime((new SimpleDateFormat(dateFormat)).parse(dataStr));
        } catch (ParseException var6) {
            var6.printStackTrace();
        }

        int d;
        if (cal.get(7) == 1) {
            d = -6;
        } else {
            d = 2 - cal.get(7);
        }

        cal.add(7, d);
        String data1 = (new SimpleDateFormat(resultDateFormat)).format(cal.getTime());
        return data1;
    }

    public static String getLastOfWeek(String dataStr, String dateFormat, String resultDateFormat) {
        Calendar cal = Calendar.getInstance();

        try {
            cal.setTime((new SimpleDateFormat(dateFormat)).parse(dataStr));
        } catch (ParseException var6) {
            var6.printStackTrace();
        }

        int d;
        if (cal.get(7) == 1) {
            d = -6;
        } else {
            d = 2 - cal.get(7);
        }

        cal.add(7, d);
        cal.add(7, 6);
        String data2 = (new SimpleDateFormat(resultDateFormat)).format(cal.getTime());
        return data2;
    }

    public static Date getDayBegin() {
        Calendar cal = new GregorianCalendar();
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal.getTime();
    }

    public static Date getDayEnd() {
        Calendar cal = new GregorianCalendar();
        cal.set(11, 23);
        cal.set(12, 59);
        cal.set(13, 59);
        return cal.getTime();
    }

    /**
     * @Description 获取几年后的日期
     * @Date 2023/10/19 16:03
     * @Author shangsheng.li
     **/
    public static Date getDateAfterYear(Date currentDate, int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        calendar.add(1, year);
        calendar.add(5, 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }

    /**
     * @Description 获取几天后的日期+1
     * @Date 2023/10/19 16:04
     * @Author shangsheng.li
     **/
    public static Date getDateAfterDays(Date currentDate, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        calendar.add(5, day + 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }

    /**
     * @Description 获取几天后的日期
     * @Date 2023/10/19 16:04
     * @Author shangsheng.li
     **/
    public static Date getDateAfterDay(Date currentDate, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        calendar.add(5, day);
        return calendar.getTime();
    }

    /**
     * @Description 获取季度
     * @Date 2023/10/19 15:51
     * @Author shangsheng.li
     **/
    public static String getQuarter(String month) {
        String quarter = "";
        int m = Integer.parseInt(month);
        if (m >= 1 && m <= 3) {
            quarter = "1";
        }

        if (m >= 4 && m <= 6) {
            quarter = "2";
        }

        if (m >= 7 && m <= 9) {
            quarter = "3";
        }

        if (m >= 10 && m <= 12) {
            quarter = "4";
        }

        return quarter;
    }

    public static List<String> getSeasonTimeLimit(String year, String quarter) {
        List<String> timeLimit = new ArrayList();
        if ("1".equals(quarter)) {
            timeLimit.add(year.concat("-01-01 00:00:00"));
            timeLimit.add(year.concat("-03-31 23:59:59"));
        } else if ("2".equals(quarter)) {
            timeLimit.add(year.concat("-04-01 00:00:00"));
            timeLimit.add(year.concat("-06-30 23:59:59"));
        } else if ("3".equals(quarter)) {
            timeLimit.add(year.concat("-07-01 00:00:00"));
            timeLimit.add(year.concat("-09-30 23:59:59"));
        } else {
            timeLimit.add(year.concat("-10-01 00:00:00"));
            timeLimit.add(year.concat("-12-31 23:59:59"));
        }

        return timeLimit;
    }

    /**
     * 判断当前时间是否在[startTime, endTime]区间，注意时间格式要一致
     *
     * @param nowTime   当前时间
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return false;
        }

        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 获取两个时间段之间的每一天
     *
     * @param beginTime 开始时间
     * @param endTime   结束时间
     * @return 结果
     */
    public static List<String> findEveryDay(String beginTime, String endTime) {
        //1.创建一个放所有日期的集合
        List<String> dates = new ArrayList();
        //2.创建时间解析对象规定解析格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        //3.将传入的时间解析成Date类型,相当于格式化
        Date dBegin = parse(beginTime, "yyyy-MM-dd");
        Date dEnd = parse(endTime, "yyyy-MM-dd");
        //4.将格式化后的第一天添加进集合
        dates.add(sdf.format(dBegin));
        //5.使用本地的时区和区域获取日历
        Calendar calBegin = Calendar.getInstance();
        //6.传入起始时间将此日历设置为起始日历
        calBegin.setTime(dBegin);
        //8.判断结束日期是否在起始日历的日期之后
        while (dEnd.after(calBegin.getTime())) {
            // 9.根据日历的规则:月份中的每一天，为起始日历加一天
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            //10.得到的每一天就添加进集合
            dates.add(sdf.format(calBegin.getTime()));
            //11.如果当前的起始日历超过结束日期后,就结束循环
        }
        return dates;
    }


}
